import { Injectable } from '@nestjs/common';
import { CreatePlanDto } from './dto/create-plan.dto';
import { UpdatePlanDto } from './dto/update-plan.dto';
import { PrismaService } from 'src/prisma/prisma.service';

@Injectable()
export class PlanService {
  constructor(private prisma: PrismaService) {}

  async create(data: CreatePlanDto) {
    return await this.prisma.plan.create({ data });
  }

  async findAll(args: Record<string, any>) {
    const { id } = args;
    return await this.prisma.plan.findMany({
      where: { lineId: +id },
      include: {
        calcBets: true,
      },
    });
  }

  async findOne(id: number) {
    return await this.prisma.plan.findFirst({
      where: { id },
      include: {
        calcBets: {
          include: {
            bet: {
              include: {
                leftTower: true,
                rightTower: true,
              },
            },
          },
        },
      },
    });
  }

  update(id: number, updatePlanDto: UpdatePlanDto) {
    return `This action updates a #${id} plan`;
  }

  async remove(id: number) {
    return await this.prisma.plan.delete({
      where: { id },
    });
  }
}
